<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="chrome=1"/>
	<meta HTTP-EQUIV="Pragma" CONTENT="no-cache"/> 
	<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache"/> 
	<meta HTTP-EQUIV="Expires" CONTENT="0"/>
    <title>Yagra重设密码</title>
	<link href="style/main.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="js/HttpRequest.js"></script>
	<script type="text/javascript" src="js/Connection.js"></script>
	<script type="text/javascript" src="js/md5-min.js"></script>
	<script language="javascript">
		 function resetPassword(){
		 	document.getElementById("errorTip").innerHTML = "";
			
		 	var oldPass = document.getElementById("oldPass").value;
			var password1 = document.getElementById("newPass1").value;
			var password2 = document.getElementById("newPass2").value;
			
			if (!oldPass || !password1 || !password2) {
				document.getElementById("errorTip").innerHTML = "字段不能为空";
				return;
			}
			
			if(password1 !== password2){
				document.getElementById("errorTip").innerHTML = "两次输入的密码不一致";
				return;
			}
			
			if(password1.length < 6){
				document.getElementById("errorTip").innerHTML = "密码长度不能少于6位";
				return;
			}
			
			var conn = new Ajax.Connection();
	
			var ran = conn.synGetString("yagra/get_random.py?ran="+Math.random(), null);
			ran = ran.trim()
			
			password = hex_md5(hex_md5(oldPass)+ran);
			
			var ret = conn.synGetString("yagra/reset_password.py?oldPass="+password+"&newPass="+password1, null);
			
			ret = ret.trim();
			
			if(ret === 'success'){
				window.location.href = "index.html"
			}	
			else{
				document.getElementById("errorTip").innerHTML = ret.substr(6);
			}
		}
		
		function reset(){
			document.getElementById("user").value = ''
			document.getElementById("pass").value = ''
		}
	</script>
</head>
<body>
	<div style="font-size:42px;font-weight:bolder;font-family:'微软雅黑'">
		Yagra
	</div>
	<br/>
	<div class="box" style="width:500px;">
		<table>
			<tr>
				<td width=100px>
		    		<span>原密码</span>
				</td>
				<td width=150px>
					<input id="oldPass" name='oldPass' type="password"  value=''></input>
				</td>
				<td>
					<div class="tips"></span>
				</td>
			</tr>		
		    <tr>
		    	<td><span id="userTip"></span></td>
		    </tr>
			<tr>
				<td width=100px>
		    		<span>新密码</span>
				</td>
				<td width=150px>
					<input id="newPass1" name='newPass1' type="password" value=''></input>
				</td>
				<td>
					<div class="tips">密码最短需要6位</span>
				</td>
			</tr>
			<tr>
				<td width=100px>
		    		<span>再次输入密码</span>
				</td>
				<td width=150px>
					<input id="newPass2" name='newPass2' type="password" value=''></input>
				</td>
				<td>
					<div class="tips"></span>
				</td>
			</tr>		
			<tr/>	
				<td colspan=3><div id="errorTip" style="color:red;"></div></td>
			</tr>
			<tr>
				<td width=100px>
					&nbsp;
				</td>
				<td width=150px>
		   		<button value="" onclick="resetPassword()">提交</button>
				</td>
				<td>
		    	<button value="" onclick="reset()">重置</button>
				</td>
			</tr>
		</table>
	</div>
</body>
</html>
